package main

import (
	"encoding/base64"
	"fmt"
	"strings"

	"gitee.com/xxhsjp/x-core/http/resty"
	"gitee.com/xxhsjp/x-core/utils/xcrypto"
)

const secret = "85ereg2e3iplm9u7"

func main() {

	// decoded := "umail_password"

	// s, _ := getEncryptedString(decoded)
	// s2, _ := getDecryptedString(s)
	// fmt.Println(s2)
	// fmt.Println(s)
	c := resty.NewDefault()
	// fmt.Println("ddddd", c.RetryCount)
	resp, err := c.R().Get("http://10.24.46.152/webmail/web/php/common/load.php?method=1")
	if err != nil {
		fmt.Println("err:", err)
	}
	fmt.Println(resp.String())
}

func getDecryptedString(str string) (string, error) {
	val := str
	prefix := "@=="
	if strings.Index(val, prefix) == 0 {
		val = strings.TrimPrefix(val, prefix)
		decoded, err := base64.StdEncoding.DecodeString(val)
		if err != nil {
			return "", err
		}
		val = string(xcrypto.Aes.DecryptCBC(decoded, []byte(secret)))
	}
	return val, nil
}

func getEncryptedString(decoded string) (string, error) {
	val := xcrypto.Aes.EncryptCBC([]byte(decoded), []byte(secret))
	return "@==" + base64.StdEncoding.EncodeToString(val), nil
}
